# -*- coding: UTF-8 -*-

"""
程序参考来源：
CSDN
原文链接：https://blog.csdn.net/weixin_39804265/article/details/105127786
python黑洞
转载链接：https://www.pythonheidong.com/blog/article/286966/ea95e533617903aed338/
"""


import xlrd
from xlutils.filter import process, XLRDReader, XLWTWriter

rb = xlrd.open_workbook('out.xls', formatting_info=True)

# 参考xlutils.copy库内的用法 参考xlutils.filter内的参数定义style_list
w = XLWTWriter()
process(XLRDReader(rb, 'unknown.xls'), w)
wb = w.output[0][1]
style_list = w.style_list

for n, sheet in enumerate(rb.sheets()):
    sheet2 = wb.get_sheet(n)
    for r in range(sheet.nrows):
        for c, cell in enumerate(sheet.row_values(r)):
            style = style_list[sheet.cell_xf_index(r, c)]
            sheet2.write(r, c, sheet.cell_xf_index(r, c), style)

wb.save('save.xls')